package com.lost.octopus.es.helper.entity.query;

import com.lost.octopus.es.helper.constant.ParameterConstant;

import java.io.Serializable;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 分页对象
 * @author zhangbh
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class PageIn implements Serializable {

    private static final long serialVersionUID = -1397859877100172759L;
    private int currentPage = ParameterConstant.DEFAULT_CURRENT_PAGE;
    private int linesPerPage = ParameterConstant.DEFAULT_LINES_PER_PAGE;

    public int getCurrentPage() {
        if (currentPage <= 0) {
            return ParameterConstant.DEFAULT_CURRENT_PAGE;
        }
        return currentPage;
    }

    public static PageIn of(int currentPage, int linesPerPage) {
        if (currentPage <= 0) {
            currentPage = ParameterConstant.DEFAULT_CURRENT_PAGE;
        }
        if (linesPerPage <= 0) {
            linesPerPage = ParameterConstant.DEFAULT_LINES_PER_PAGE;
        }
        return new PageIn(currentPage, linesPerPage);
    }


}
